/*
	深度拷贝
*/

#include <iostream>
#include <cstring>
using namespace std;

class Student {
	private:
		char * name;
	
	public:
		Student(const char * n) {
			cout << "Constructing..." << endl;
			name = new char[strlen(n)+1];
			strcpy(name, n);
			// name[strlen(n)] = '\0';
		}
		~Student() {
			cout << "Destroying..." << endl;
			delete []name;
		}
		Student(const Student & obj); 
		friend ostream & operator << (ostream & stream, const Student & obj); 
};

Student::Student(const Student & obj) {
	cout << "Copy Constructing..." << endl;
	name = new char[strlen(obj.name)+7+1];
	strcpy(name, "Copy of ");
	strcat(name, obj.name);
}

ostream & operator << (ostream & stream, const Student & obj) {
	stream << obj.name;

	return stream;
}

int main(int argc, char * argv[]) {
	Student s1("xxxxxx");
	
	cout << s1 << endl;

	Student s2(s1);

	cout << s2 << endl;

	return 0;
}
